# Maintainer: Dave Reisner <dreisner@archlinux.org>

pkgname=systemd-git
pkgver=217.489.gbf257ae
pkgrel=1
pkgdesc="system and service manager"
arch=('i686' 'x86_64')
url="http://www.freedesktop.org/wiki/Software/systemd"
license=('GPL2' 'LGPL2.1' 'MIT')
depends=('acl' 'elfutils' 'glib2' 'hwids' 'kbd' 'kmod' 'libcap' 'libseccomp' 'libgcrypt' 'pam' 'util-linux' 'xz')
makedepends=('docbook-xsl' 'git' 'gobject-introspection' 'gperf' 'gtk-doc' 'intltool' 'libxslt')
provides=('systemd' 'libsystemd' 'nss-myhostname' 'systemd-sysvcompat' 'systemd-tools' 'udev=999')
conflicts=('systemd' 'libsystemd' 'nss-myhostname' 'systemd-sysvcompat' 'systemd-tools' 'sysvinit' 'initscripts' 'udev')
groups=('systemd')
options=('!libtool' '!strip')
backup=(etc/dbus-1/system.d/org.freedesktop.systemd1.conf
        etc/dbus-1/system.d/org.freedesktop.hostname1.conf
        etc/dbus-1/system.d/org.freedesktop.login1.conf
        etc/dbus-1/system.d/org.freedesktop.locale1.conf
        etc/dbus-1/system.d/org.freedesktop.machine1.conf
        etc/dbus-1/system.d/org.freedesktop.timedate1.conf
        etc/pam.d/systemd-user
        etc/systemd/bootchart.conf
        etc/systemd/coredump.conf
        etc/systemd/journal-upload.conf
        etc/systemd/journald.conf
        etc/systemd/logind.conf
        etc/systemd/resolved.conf
        etc/systemd/system.conf
        etc/systemd/timesyncd.conf
        etc/systemd/user.conf
        etc/udev/udev.conf)
install='systemd.install'
source=('git://anongit.freedesktop.org/systemd/systemd.git'
        'initcpio-hook-udev'
        'initcpio-install-udev'
        'initcpio-install-systemd')
md5sums=('SKIP'
         '29245f7a240bfba66e2b1783b63b6b40'
         'bde43090d4ac0ef048e3eaee8202a407'
         '107c489f27c667be4101aecd3369b355')
sha512sums=('SKIP'
            'f74bf69800af33a2913ab782b6f2c75369f27b1a23fbce2a361a91fca2b0c95c2579e6544cd1b5547a7092305e7a4cb3145ae650e325ce4b60f25aa0a81b1536'
            '6bec5285484d2204633cab37a598706d15b49c7941a786be1f86e5326222b4c3eee67cce76bb26494ae9073d261a3bb22a94d1e18ce308bb6fed6d1210f9853b'
            '32dd6a62c6bb0bc3c38ffad05b3191af24111a7f7f8ac220667a6366ce1ff342275bf0e2639268b4681db3e8dbc3074607fe5c7d71b5b93bc60d47b22e644029')


pkgver() {
  cd 'systemd'
  git describe | sed 's/^v//;s/-/./g'
}

build() {
  cd 'systemd'

  local timeservers=({0..3}.arch.pool.ntp.org)

  ./autogen.sh
  ./configure \
      --libexecdir=/usr/lib \
      --localstatedir=/var \
      --sysconfdir=/etc \
    --enable-option-checking \
    --enable-libtool-lock \
    --disable-nls \
      --enable-gtk-doc \
      --enable-introspection \
    --enable-address-sanitizer \
      --enable-compat-libs \
    --disable-coverage \
      --disable-ima \
    --disable-apparmor \
      --disable-audit \
      --disable-multi-seat-x \
      --disable-smack \
    --disable-efi \
    --disable-hibernate \
      --with-sysvinit-path= \
      --with-sysvrcnd-path= \
      --with-firmware-path="/usr/lib/firmware/updates:/usr/lib/firmware" \
      --with-ntp-servers="${timeservers[*]}"

  make -j4
}

package() {
  make -C "systemd" DESTDIR="$pkgdir" install

  rm -r "$pkgdir/usr/lib/rpm/macros.d"

  for tool in runlevel reboot shutdown poweroff halt telinit; do
    ln -s 'systemctl' "$pkgdir/usr/bin/$tool"
  done
  ln -s '../lib/systemd/systemd' "$pkgdir/usr/bin/init"

  # fix .so links in manpage stubs
  find "$pkgdir/usr/share/man" -type f -name '*.[[:digit:]]' \
      -exec sed -ri '1s|^\.so (.*)\.([0-9]+)|.so man\2/\1.\2|' {} +

  # don't write units to /etc by default
  rm "$pkgdir/etc/systemd/system/getty.target.wants/getty@tty1.service" \
      "$pkgdir/etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service" \
      "$pkgdir/etc/systemd/system/multi-user.target.wants/systemd-networkd.service" \
      "$pkgdir/etc/systemd/system/multi-user.target.wants/systemd-resolved.service" \
      "$pkgdir/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service"
  rmdir "$pkgdir/etc/systemd/system/getty.target.wants"

  # Replace dialout/tape/cdrom group in rules with uucp/storage/optical group
  sed -i 's#GROUP="dialout"#GROUP="uucp"#g;
          s#GROUP="tape"#GROUP="storage"#g;
          s#GROUP="cdrom"#GROUP="optical"#g' \
            "$pkgdir"/usr/lib/udev/rules.d/*.rules \
            "$pkgdir"/usr/lib/sysusers.d/basic.conf

  # ensure proper permissions for /var/log/journal
  chown root:systemd-journal "$pkgdir/var/log/journal"
  chmod 2755 "$pkgdir/var/log/journal"

  # fix systemd-user PAM
  sed -i 's|system-auth|system-login|g' "$pkgdir/etc/pam.d/systemd-user"

  # add mkinitcpio hooks
  install -Dm644 "$srcdir/initcpio-install-systemd" "$pkgdir/usr/lib/initcpio/install/systemd"
  install -Dm644 "$srcdir/initcpio-install-udev" "$pkgdir/usr/lib/initcpio/install/udev"
  install -Dm644 "$srcdir/initcpio-hook-udev" "$pkgdir/usr/lib/initcpio/hooks/udev"
}
